var api = require("api");
var util=require("../utils/util");

// 知识库分类
function get_base_category() {
  return new Promise((resolve,reject)=>{
    wx.request({
      url: api.data.requestUrl + api.data.baseCategory,
      header: {
        'content-type': 'application/json;charset=UTF-8'
      },
      method: 'GET',
      success: function (res) {
        resolve(res);
        util.show_success_toast(res)
      },
      fail: function () {
        reject();
        util.show_fail_toast()
      },
    })
  })
}
// 知识库列表
function get_base_list(params) {
  return new Promise((resolve,reject)=>{
    wx.request({
      url: api.data.requestUrl + api.data.baseList,
      header: {
        'content-type': 'application/json;charset=UTF-8'
      },
      method: 'GET',
      data: params,
      success: function (res) {
        resolve(res);
        util.show_success_toast(res)
      },
      fail: function () {
        reject();
        util.show_fail_toast()
      },
    })
  })
}
// 知识库详情
function get_base_detail(params) {
  return new Promise((resolve,reject)=>{
    wx.request({
      url: api.data.requestUrl + api.data.baseDetail,
      header: {
        'content-type': 'application/json;charset=UTF-8',
        'x-access-token': wx.getStorageSync('token')?wx.getStorageSync('token'):''
      },
      method: 'GET',
      data: params,
      success: function (res) {
        resolve(res);
        util.show_success_toast(res)
      },
      fail: function () {
        reject();
        util.show_fail_toast()
      },
    })
  })
}
// 知识库评论列表
function get_comment_list(params) {
  return new Promise((resolve,reject)=>{
    wx.request({
      url: api.data.requestUrl + api.data.getCommentList,
      header: {
        'content-type': 'application/json;charset=UTF-8',
        'x-access-token': wx.getStorageSync('token')?wx.getStorageSync('token'):''
      },
      method: 'GET',
      data: params,
      success: function (res) {
        resolve(res);
        util.show_success_toast(res)
      },
      fail: function () {
        reject();
        util.show_fail_toast()
      },
    })
  })
}
// 知识库收藏
function add_call_base(params,token) {
  return new Promise((resolve,reject)=>{
    wx.request({
      url: api.data.requestUrl + api.data.callBase,
      header: {
        'content-type': 'application/json;charset=UTF-8',
        'x-access-token': token
      },
      method: 'POST',
      data: params,
      success: function (res) {
        resolve(res);
        util.show_success_toast(res)
      },
      fail: function () {
        reject();
        util.show_fail_toast()
      },
    })
  })
}
// 知识库取消收藏
function cancel_call_base(params,token) {
  return new Promise((resolve,reject)=>{
    wx.request({
      url: api.data.requestUrl + api.data.cancelCallBase,
      header: {
        'content-type': 'application/json;charset=UTF-8',
        'x-access-token': token
      },
      method: 'GET',
      data: params,
      success: function (res) {
        resolve(res);
        util.show_success_toast(res)
      },
      fail: function () {
        reject();
        util.show_fail_toast()
      },
    })
  })
}
// 知识库/回复评论
function add_comment(params,token) {
  return new Promise((resolve,reject)=>{
    wx.request({
      url: api.data.requestUrl + api.data.addBaseComment,
      header: {
        'content-type': 'application/json;charset=UTF-8',
        'x-access-token': token
      },
      method: 'POST',
      data: params,
      success: function (res) {
        resolve(res);
        util.show_success_toast(res)
      },
      fail: function () {
        reject();
        util.show_fail_toast()
      },
    })
  })
}
// 知识库/评论点赞
function add_praise(params,token) {
  return new Promise((resolve,reject)=>{
    wx.request({
      url: api.data.requestUrl + api.data.addPraise,
      header: {
        'content-type': 'application/json;charset=UTF-8',
        'x-access-token': token
      },
      method: 'POST',
      data: params,
      success: function (res) {
        resolve(res);
        util.show_success_toast(res)
      },
      fail: function () {
        reject();
        util.show_fail_toast()
      },
    })
  })
}
// 知识库/评论点赞取消
function cancel_praise(params,token) {
  return new Promise((resolve,reject)=>{
    wx.request({
      url: api.data.requestUrl + api.data.cancelPraise,
      header: {
        'content-type': 'application/json;charset=UTF-8',
        'x-access-token': token
      },
      method: 'GET',
      data: params,
      success: function (res) {
        resolve(res);
        util.show_success_toast(res)
      },
      fail: function () {
        reject();
        util.show_fail_toast()
      },
    })
  })
}
// 知识库浏览
function add_browse(params) {
  return new Promise((resolve,reject)=>{
    wx.request({
      url: api.data.requestUrl + api.data.addBrowse,
      header: {
        'content-type': 'application/json;charset=UTF-8',
        'x-access-token': wx.getStorageSync('token')?wx.getStorageSync('token'):''
      },
      method: 'POST',
      data: params,
      success: function (res) {
        resolve(res);
        // util.show_success_toast(res)
      },
      fail: function () {
        reject();
        // util.show_fail_toast()
      },
    })
  })
}
// 知识库分享
function add_share(params) {
  return new Promise((resolve,reject)=>{
    wx.request({
      url: api.data.requestUrl + api.data.addShare,
      header: {
        'content-type': 'application/json;charset=UTF-8',
        'x-access-token': wx.getStorageSync('token')?wx.getStorageSync('token'):''
      },
      method: 'POST',
      data: params,
      success: function (res) {
        resolve(res);
        util.show_success_toast(res)
      },
      fail: function () {
        reject();
        util.show_fail_toast()
      },
    })
  })
}
// 删除评论
function del_comment(params) {
  return new Promise((resolve,reject)=>{
    wx.request({
      url: api.data.requestUrl + api.data.delComment,
      header: {
        'content-type': 'application/json;charset=UTF-8',
        'x-access-token': wx.getStorageSync('token')?wx.getStorageSync('token'):''
      },
      method: 'GET',
      data: params,
      success: function (res) {
        resolve(res);
        util.show_success_toast(res)
      },
      fail: function () {
        reject();
        util.show_fail_toast()
      },
    })
  })
}

module.exports={
  get_base_category,
  get_base_list,
  get_base_detail,
  get_comment_list,
  add_call_base,
  cancel_call_base,
  add_comment,
  add_praise,
  cancel_praise,
  add_browse,
  add_share,
  del_comment
}